home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / intuition / BoopsiGadget_test.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  6.7 KB  |  249 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/intuition/BoopsiGadget_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.7 $
  9.  *    $Date: 1994/07/23 19:15:11 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/SignalResponder.h>
  16. #include <APlusPlus/intuition/GWindow.h>
  17. #include <APlusPlus/intuition/BoopsiGadget.h>
  18. #include <APlusPlus/intuition/StdGadget.h>
  19. #include <APlusPlus/intuition/IntuiMessageC.h>
  20. #include <APlusPlus/graphics/GBorder.h>
  21. #include <APlusPlus/intuition/ITransponder.h>
  22.  
  23. extern "C" {
  24. #include <dos/dos.h>
  25. }
  26. #include <stdio.h>
  27.  
  28.  
  29. static const char rcs_id[] = "$Id: BoopsiGadget_test.cxx,v 1.7 1994/07/23 19:15:11 Armin_Vogt Exp Armin_Vogt $";
  30.  
  31.  
  32. // A customized Boopsi Proportional Gadget class that defines default attributes.
  33. class MyProp : public BoopsiGadget
  34. {
  35.    public:
  36.       MyProp(GOB_OWNER,AttrList& attrs)
  37.       : BoopsiGadget(gob_owner,(UBYTE*)"propgclass",attrs) 
  38.       {
  39.          // set the default values of class 'MyProp'.
  40.          // Base class values are overwritten! Class-user values do override!
  41.          applyDefaultAttrs( attrs, AttrList(
  42.             GA_Immediate,  TRUE,
  43.             GA_RelVerify,  TRUE,
  44.             ICA_TARGET,    ICTARGET_IDCMP,
  45.             PGA_NewLook,   TRUE,
  46.             TAG_END) );            
  47.       }
  48.       ~MyProp() {}
  49.          
  50.       // runtime type inquiry support
  51.       static const Intui_Type_info info_obj;
  52.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  53.          { return info_obj; }
  54.       static const Type_info& info()                // get the 'type_id' of a specific class
  55.          { return info_obj; }
  56.  
  57. };
  58.  
  59. intui_typeinfo(MyProp, derived(from(BoopsiGadget)), rcs_id);
  60.  
  61.  
  62. BOOL running = TRUE;
  63. BOOL close2 = FALSE;
  64. GWindow* stop_window;
  65.  
  66.  
  67. class MySRSP : public SignalResponder
  68. {
  69.    public:
  70.       MySRSP(BYTE signal) : SignalResponder(signal,0) {}
  71.  
  72.       void actionCallback();
  73. };
  74.  
  75. // Overwrite the virtual 'signal received' action callback method.
  76. // This SignalResponder work with a global variable (not so VERY object-oriented).
  77. void MySRSP::actionCallback()
  78. {
  79.    puts("**Break\n");
  80.    running = FALSE;
  81. }
  82.  
  83. class MyWindow : public GWindow
  84. {
  85.    private:
  86.       void init();
  87.  
  88.    public:
  89.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs) { init(); }
  90.       void On_CLOSEWINDOW(const IntuiMessageC* msg);
  91.       void On_ACTIVEWINDOW(const IntuiMessageC* msg);
  92.       void On_SIZEVERIFY(const IntuiMessageC* msg);
  93.       void handleIntuiMsg(const IntuiMessageC* imsg);
  94.  
  95.       // runtime type inquiry support
  96.       static const Intui_Type_info info_obj;
  97.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  98.          { return info_obj; }
  99.       static const Type_info& info()                // get the 'type_id' of a specific class
  100.          { return info_obj; }
  101.  
  102. };
  103.  
  104. intui_typeinfo(MyWindow, derived(from(GWindow)), rcs_id);
  105.  
  106.  
  107. void MyWindow::init()
  108. {
  109.    // make sure these IDCMP messages will be received
  110.    modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY);
  111. }
  112.  
  113. void MyWindow::On_CLOSEWINDOW(const IntuiMessageC* msg)
  114.       {
  115.          puts("CLOSEWINDOW.\n");
  116.          if (this == stop_window) running = FALSE;
  117.          delete this;
  118.       }
  119. void MyWindow::On_ACTIVEWINDOW(const IntuiMessageC* msg)
  120.       {
  121.          ULONG dummy=0;
  122.          printf("%s is ACTIVE.\n",getAttribute(WA_Title,dummy));
  123.       }
  124. void MyWindow::On_SIZEVERIFY(const IntuiMessageC* msg)
  125.       {
  126.          puts("SIZEVERIFY. \n");
  127.       }
  128. void MyWindow::handleIntuiMsg(const IntuiMessageC* imsg)
  129.       {
  130.          switch (imsg->getClass())
  131.          {
  132.             case CLASS_CLOSEWINDOW :
  133.                On_CLOSEWINDOW(imsg); break;
  134.             case CLASS_ACTIVEWINDOW :
  135.                On_ACTIVEWINDOW(imsg); break;
  136.             case CLASS_SIZEVERIFY :
  137.                On_SIZEVERIFY(imsg); break;
  138.          }
  139.          GWindow::handleIntuiMsg(imsg);
  140. }
  141.  
  142. // This ITransponder multiplies received PGA_Top values with a given factor.
  143. class PropScalarITP : public ITransponder
  144. {
  145.    private:
  146.       FLOAT factor;
  147.  
  148.       void sendNotification(AttrList& attrs)
  149.       {
  150.          AttrManipulator next(attrs);
  151.          // ONLY transmit those Attribute Tags that you really WANT to change!
  152.          if (next.findTagItem(PGA_Top) )
  153.          {
  154.             if (APPOK(receiver1)) receiver1->setAttributes( AttrList(
  155.                PGA_Top, (LONG)((FLOAT)next.data()*factor),
  156.                TAG_END
  157.                ) );
  158.          }
  159.       }
  160.    public:
  161.       PropScalarITP(FLOAT f,IntuiObject* receiver=NULL) { factor = f; receiver1 = receiver; }
  162. };
  163.  
  164.  
  165.  
  166. void APPmain(int argc,char* argv[])
  167. {
  168.    ULONG l=0;     // dummy variable needed for a getAttribute() call
  169.    MySRSP sr(SIGBREAKB_CTRL_C);
  170.  
  171.    PropScalarITP prop2to1_itp(0.5);
  172.    PropScalarITP prop1to2_itp(2);
  173.  
  174.    NeXTBorder border;
  175.  
  176.  
  177.    MyWindow* little = new MyWindow(OWNER_NULL,
  178.       AttrList( WA_Title,(ULONG)"Window - close this to stop.",
  179.       WA_Left,    200,
  180.       WA_Top,     50,
  181.       WA_Width,   300,
  182.       WA_Height,  150,
  183.       WA_MinHeight,  100,
  184.       WA_MinWidth,   100,
  185.       WA_MaxHeight,  1600,
  186.       WA_MaxWidth,   1600,
  187.       TAG_END) );
  188.  
  189.  
  190.    MyWindow* small = new MyWindow(little,
  191.       AttrList( WCV_SharePortWithWindowObj(little),
  192.       WA_Title,(ULONG)"Window sharing userport",
  193.       WA_Left,    200,
  194.       WA_Top,     200,
  195.       WA_Width,   200,
  196.       WA_Height,  150,
  197.       WA_MinHeight,  100,
  198.       WA_MinWidth,   100,
  199.       WA_MaxHeight,  1600,
  200.       WA_MaxWidth,   1600,
  201.       TAG_END) );
  202.  
  203.  
  204.    MyProp* prop1 = new MyProp(small,
  205.       AttrList( GOB_LeftFromRightOfParent,-30,
  206.       GOB_TopFromTopOfParent,       0,
  207.       GOB_RightFromRightOfParent,   -1,
  208.       GOB_BottomFromBottomOfParent, 0,
  209.       PGA_Freedom,   FREEVERT,
  210.       PGA_Top,    10,
  211.       PGA_Total,  100,
  212.       PGA_Visible,50,
  213.       ITRANSPONDER(&prop1to2_itp),
  214.       GOB_BorderObj(&border),
  215.       TAG_END) );
  216.  
  217.  
  218.    MyProp* prop2 = new MyProp(little,
  219.       AttrList(
  220.       GOB_LeftFromLeftOfParent,  2,
  221.       GOB_TopFromTopOfParent,    2,
  222.       GOB_RightFromLeftOfParent, 35,
  223.       GOB_BottomFromBottomOfParent, -10,
  224.       PGA_Freedom,   FREEVERT,
  225.       PGA_Top,    prop1->getAttribute(PGA_Top,l)*2,   // initialise from the ITP source
  226.       PGA_Total,  200,
  227.       PGA_Visible,100,
  228.       GOB_BorderObj(&border),
  229.       ITRANSPONDER(&prop2to1_itp),
  230.       TAG_END) );
  231.  
  232.  
  233.    prop1to2_itp.setReceiver(prop2);
  234.    prop2to1_itp.setReceiver(prop1);
  235.  
  236.    stop_window = little;
  237.    
  238.    // redraw the window contents
  239.    little->refreshGList();
  240.    small->refreshGList();
  241.  
  242.    while (running)
  243.    {
  244.       SignalResponder::WaitSignal();
  245.    }
  246.  
  247.    puts("cleaned up. goodbye.\n");
  248. }
  249.